/****************************************************************
Architecture:
Mohammad Ashraful Alam, Microsoft MVP 2007-2010
Portfolio: http://www.ashraful.net
***************************************************************/
using System.Data;
using System.Collections.Generic;
using System;

namespace DaXDD.DataContainers.Model
{
    public class Employee
    {
        /// <summary>
        /// This constant is being used by the crud methods, to validate EmployeeId parameter 
        /// </summary>
        public const int EmployeeIdMinValue = 0;

        #region Employee Related Collections

        public static List<Employee> GenerateEmployeeCollectionFromReader(IDataReader returnData)
        {

            List<Employee> colEmployee = new List<Employee>();
            while (returnData.Read())
            {
                Employee newEmployee = new Employee
                {
                    EmployeeId = returnData["EmployeeId"] == System.DBNull.Value ? EmployeeIdMinValue : (int)returnData["EmployeeId"],
                    LastName = returnData["LastName"] == System.DBNull.Value ? null : (string)returnData["LastName"],
                    FirstName = returnData["FirstName"] == System.DBNull.Value ? null : (string)returnData["FirstName"],
                    Title = returnData["Title"] == System.DBNull.Value ? null : (string)returnData["Title"],
                    TitleOfCourtesy = returnData["TitleOfCourtesy"] == System.DBNull.Value ? null : (string)returnData["TitleOfCourtesy"],
                    BirthDate = returnData["BirthDate"] == System.DBNull.Value ? DateTime.MinValue : (DateTime)returnData["BirthDate"],
                    HireDate = returnData["HireDate"] == System.DBNull.Value ? DateTime.MinValue : (DateTime)returnData["HireDate"],
                    Address = returnData["Address"] == System.DBNull.Value ? null : (string)returnData["Address"],
                    City = returnData["City"] == System.DBNull.Value ? null : (string)returnData["City"],
                    Region = returnData["Region"] == System.DBNull.Value ? null : (string)returnData["Region"],
                    PostalCode = returnData["PostalCode"] == System.DBNull.Value ? null : (string)returnData["PostalCode"],
                    Country = returnData["Country"] == System.DBNull.Value ? null : (string)returnData["Country"],
                    HomePhone = returnData["HomePhone"] == System.DBNull.Value ? null : (string)returnData["HomePhone"],
                    Extension = returnData["Extension"] == System.DBNull.Value ? null : (string)returnData["Extension"],
                    Photo = returnData["Photo"] == System.DBNull.Value ? null : (byte[])returnData["Photo"],
                    Notes = returnData["Notes"] == System.DBNull.Value ? null : (string)returnData["Notes"],
                    ReportsTo = returnData["ReportsTo"] == System.DBNull.Value ? EmployeeIdMinValue : (int)returnData["ReportsTo"],
                    PhotoPath = returnData["PhotoPath"] == System.DBNull.Value ? null : (string)returnData["PhotoPath"]

                };

                //adding the Employee to the collection
                colEmployee.Add(newEmployee);
            }

            //returns the collection of Employee objects
            return (colEmployee);

        }//GenerateEmployeeCollectionFromReader

        #endregion
    }
}
